﻿@model WaiGaoQiaoWeb.Models.PostVM
@{
    ViewBag.Title = "AddPost";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section Head
{
    <script type="text/javascript">
        $(document).ready(function () {
            $("form").makeValidationInline();

            if ($("#Work_postStructrueId1").val() != "0") {
                $.post('@Url.Action("RtnPostName", "Post")', { "Id": $("#Work_postStructrueId1").val() }, function (data) {
                    $("#Work_postStructrueName").val(data);
                    $("#Work_postStructrueId").val($("#Work_postStructrueId1").val())
                });
            }
            if ($("#Work_ArticleInfoID1").val() != "0") {

                $.post('@Url.Action("RtnArticleName", "Post")', { "Id": $("#Work_ArticleInfoID1").val() }, function (data) {
                    $("#Work_ArticleInfoArticleName").val(data);
                    $("#Work_ArticleInfoID").val($("#Work_ArticleInfoID1").val())
                });
            }
            //保存
            $("#btnSave").click(function (event) {

                if (!validate()) {
                    return false;
                }
                if (!$("#fmEdit").valid()) {
                    return false;
                }
                $('#fmEdit').ajaxSubmit(function (callback) {
                    if (callback) {
                        $(":input").each(function () {
                            if ($(this).attr("type") == "text" || $(this).attr("type") == "textarea") {
                                $(this).val("");
                            }
                        });
                        $("#GiveCount").focus();
                        CloseModelWindow(null, true);
                    }
                });
            }); // end of btnSave

            //关闭
            $("#btnCancel").click(function (e) {
                $(":input").each(function () {
                    if ($(this).attr("type") == "text" || $(this).attr("type") == "textarea") {
                        $(this).val("");
                    }
                });
                $("#GiveCount").focus();
                CloseModelWindow(null, true);
            });
            function validate() {

                var Work_postStructrueId = $("#Work_postStructrueId").val();
                var Work_ArticleInfoID = $("#Work_ArticleInfoID").val();
                var Work_postStructrueId1 = $("#Work_postStructrueId1").val();
                var Work_ArticleInfoID1 = $("#Work_ArticleInfoID1").val();
                if (Work_postStructrueId == "0") {
                    showLoadingMsg("请选择岗位名称", { left: 300, top: 2 }, true, 3000);
                    return false;
                }
                if (Work_ArticleInfoID == "0") {
                    showLoadingMsg("请选择物品名称", { left: 300, top: 2 }, true, 3000);
                    return false;
                }
                if (Work_ArticleInfoID != "0" && Work_postStructrueId != "0") {
                    if (Work_postStructrueId1 == Work_postStructrueId && Work_ArticleInfoID == Work_ArticleInfoID1) {
                        return true;
                    }
                    else {
                        var rtn = false;
                        $.ajax({
                            type: "POST",
                            url: '@Url.Action("Validate", "Post")',
                            async: false,
                            data: { "postId": Work_postStructrueId, "articleId": Work_ArticleInfoID },
                            success: function (msg) {
                                rtn = msg;
                                if (msg) {
                                    return true;
                                }
                                else {
                                    showLoadingMsg("该岗位已经定义了这个物品，请选择其他物品", { left: 300, top: 2 }, true, 3000);
                                    return false;
                                }
                            }
                        });

                        return rtn;
                    }
                }

            }

        });
    </script>
}
@using (Html.BeginForm("SaveWork_Post", "Post", FormMethod.Post, new { id = "fmEdit" }))
{
    @Html.ValidationSummary(true)
    <div class="mainpanel">
        @Html.HiddenFor(model => model.ID)
        <table style="width: 88%;">
            <tr>
                <td colspan="4">
                    <br />
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td style="text-align: right;">@Html.LabelFor(model => model.PostId)
                </td>
                <td>
                    @Html.Partial("RtnPostNameList", new Model.WaiGaoQiao.Work_post())
                    @Html.HiddenFor(model => model.Work_postStructrueId1)
                    @Html.ValidationMessageFor(model => model.Work_postStructrueId)<span style="color: Red;">*</span>
                </td>
                <td style="text-align: right;">@Html.LabelFor(model => model.ArticleId)
                </td>
                <td>
                    @Html.Partial("RtnWorkArticleList", new Model.WaiGaoQiao.Work_ArticleInfo())
                    @Html.HiddenFor(model => model.Work_ArticleInfoID1)
                    @Html.ValidationMessageFor(model => model.Work_ArticleInfoID)<span style="color: Red;">*</span>
                </td>
            </tr>
            <tr>
                <td style="text-align: right;">@Html.LabelFor(model => model.RuleId)
                </td>
                <td>
                    @Html.DropDownListFor(model => model.RuleId, ViewBag.Rule as IEnumerable<SelectListItem>, new { @style = "width:160px" })
                </td>
                <td style="text-align: right;">@Html.LabelFor(model => model.GiveCount)
                </td>
                <td>
                    @Html.TextBoxFor(model => model.GiveCount)
                </td>
            </tr>
        </table>
        <div class="buttonpanel">
            <div style="float: right; margin-right: 10px;">
                <a id="btnSave" href="javascript:void(0);" class="button"><span>保存</span></a> <a
                    id="btnCancel" href="javascript:void(0);" class="button"><span>关闭</span></a>
            </div>
        </div>
    </div>
}
